package com.hiwhitley.easy.day14;

import java.util.Stack;

/**
 * Created by hiwhitley on 2016/8/18.
 */
public class MyQueue {
    Stack stack1 = new Stack();
    Stack stack2 = new Stack();

    // Push element x to the back of queue.
    public void push(int x) {
        if (stack1.empty()) {
            stack1.add(x);
        } else {
            while (!stack1.empty()) {
                stack2.add(stack1.pop());
            }
            stack1.add(x);
            while (!stack2.empty()) {
                stack1.add(stack2.pop());
            }
        }
    }

    // Removes the element from in front of queue.
    public void pop() {
        stack1.pop();
    }

    // Get the front element.
    public int peek() {
        return (int) stack1.peek();
    }

    // Return whether the queue is empty.
    public boolean empty() {
        return stack1.empty();
    }
}
